package cn.stylefeng.guns.modular.api;

import cn.stylefeng.guns.modular.bshuser.entity.BshUsers;
import cn.stylefeng.guns.modular.bshuser.service.BshUsersService;
import cn.stylefeng.guns.modular.homeconfig.entity.HomeConfig;
import cn.stylefeng.guns.modular.homeconfig.service.HomeConfigService;
import cn.stylefeng.guns.modular.linelunbo.entity.LineBanner;
import cn.stylefeng.guns.modular.linelunbo.service.LineBannerService;
import cn.stylefeng.guns.modular.redline.entity.Redline;
import cn.stylefeng.guns.modular.redline.service.RedlineService;
import cn.stylefeng.guns.modular.shangxin.entity.Shangxin;
import cn.stylefeng.guns.modular.shangxin.service.ShangxinService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/webapi")
public class ApiController  extends BaseController {

    @Autowired
    private RedlineService redlineService;

    @Autowired
    private LineBannerService lineBannerService;

    @Autowired
    private BshUsersService bshUsersService;
    @Autowired
    private HomeConfigService homeConfigService;
    @Autowired
    private ShangxinService shangxinService;

    @RequestMapping("/getredline")
    @ResponseBody
    public ResponseData getredline() {

        List<Redline> lr = redlineService.list(new QueryWrapper<Redline>()
                .select("id","name","mianPic","ms","tags","jiage")
                .eq("isdel",0));

        return ResponseData.success(lr);
    }

    @RequestMapping("/getredlineById")
    @ResponseBody
    public ResponseData getredlineById(Long id) {
        Redline rl = redlineService.getById(id);
        return ResponseData.success(rl);
    }

    @RequestMapping("/getbanner")
    @ResponseBody
    public ResponseData getbanner() {
        List<LineBanner> ll = lineBannerService.list();
        return ResponseData.success(ll);
    }



    /**
     * 点击登录执行的动作
     *
     * @author Dong
     * @Date 2018/12/23 5:42 PM
     */
    @RequestMapping("/getUserInfo")
    @ResponseBody
    public ResponseData getUserInfo(String token) {
        String siteId = "310113";

        BshUsers bu = bshUsersService.getUserByToken(token,siteId);

        return ResponseData.success(bu);
    }


    @RequestMapping("/getHomeConfig")
    @ResponseBody
    public ResponseData getHomeConfig() {
        HomeConfig hc = homeConfigService.getById(1);
        return ResponseData.success(hc);
    }


    @RequestMapping("/getShangxin")
    @ResponseBody
    public ResponseData getShangxin() {
        List<Shangxin> lsx = shangxinService.list();
        return ResponseData.success(lsx);
    }


}
